package com.helsinki.mapper;

import com.helsinki.pojo.Product;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;


public interface ProductMapper {
    // 根据id查询商品
    @Select("select * from product where id = #{id}")
    Product findById(String id);

    // 查询所有商品
    @Select("select * from product")
    List<Product> findAll();

    //添加商品
    @Insert("insert into product (id,productNum, productName, cityName, departureTime,productPrice,productDesc,productStatus) " +
            "values(#{id},#{productNum},#{productName},#{cityName},#{departureTime},#{productPrice},#{productDesc},#{productStatus})")
    void addProduct(Product product);

    //删除商品
    @Delete("delete from product where id = #{id}")
    void deleteById(String id);

    //更新商品信息
    @Update("update product set " +
            "productNum = #{productNum}," +
            "productName = #{productName}, " +
            "cityName = #{cityName}, " +
            "departureTime = #{departureTime}," +
            "productPrice = #{productPrice}," +
            "productDesc = #{productDesc}," +
            "productStatus = #{productStatus} " +
            "where id = #{id}")
    void updateById(Product product);

    //模糊查询


    //更改产品状态
    @Update("update product set productStatus = #{status} where id = #{id}")
    void updateStatus(@Param("id") String id,
                      @Param("status") int status);



    @Update("SET foreign_key_checks = 0")
    void closeForeignKey();
    @Update("SET foreign_key_checks = 1")
    void openForeignKey();
}
